var express = require('express');
var bodyParser=require('body-parser');
var app = express();
app.use(express.static('html'));
app.use(bodyParser.urlencoded({extended:true}));
var fs = require('fs');

app.get('/',function(req,res){
	res.send('');
})

var server = app.listen(8081,function(){
	var host = server.address().address
	  var port = server.address().port
	 
	  console.log("应用实例，访问地址为 http://%s:%s", host, port)
	  var data = [{'name':'123','rq':'2018-04-15','jbstart':'08:18','jbend':'16:00','type':'1','total':'7'},
		{'name':'1234','rq':'2018-03-18','jbstart':'08:18','jbend':'18:00','type':'2','total':'6'},
		{'name':'1235','rq':'2018-02-11','jbstart':'08:18','jbend':'18:00','type':'1','total':'6'},
		{'name':'1236','rq':'2018-01-12','jbstart':'08:18','jbend':'15:00','type':'2','total':'6'}];
		fs.readdir('E:\\其他开发\\node.js\\project4\\datas','utf-8',function(err,info){
			if(info != undefined && info != null){
			var dataLen = data.length;
				for(var i=0;i<dataLen;i++){
					var cdata = data[i];
					var name = cdata['name'];
					var rq = cdata['rq'];
					var newJson = {'jbstart':cdata['jbstart'],'jbend':cdata['jbend'],'type':cdata['type'],'total':cdata['total']};
					var cpath = '\\datas\\'+name;
					if(!fs.existsSync(cpath)){
						fs.mkdirSync(cpath);
					}
					var cpathd = cpath + "\\" + rq + ".json";
					fs.writeFileSync(cpathd,JSON.stringify(newJson));
				}
			}
		});
		/*fs.readFile('E:\\其他开发\\node.js\\project4\\datas\\aaa.txt','utf-8',function(err,info){
			console.log(info);
		});*/
})